package com.cinyi.cyds.util;

import java.util.ResourceBundle;

import org.apache.log4j.Logger;

/**
 * 项目参数工具类
 * 
 * @author core-system-dev
 * 
 */
public class ConfigUtil {
	private final static Logger log = Logger.getLogger(ConfigUtil.class);
	private static final ResourceBundle bundle = java.util.ResourceBundle.getBundle("config");

	/**
	 * 获得sessionInfo名字
	 * 
	 * @return
	 */
	public static final String getSessionInfoName() {
		return bundle.getString("sessionInfoName");
	}

	/**
	 * 通过键获取值
	 * 
	 * @param key
	 * @return
	 */
	public static final String get(String key) {
		return get(key,null) ;
	}
	
	public static final String getString(String key,String def) {
		return get(key, def);
	}
	public static final String get(String key,String def) {
		if(!bundle.containsKey(key)){
			return def ;
		}
		try{
			return bundle.getString(key);
		}catch(Exception e){
			log.error( key + " not found:" + e.getMessage() );
		}
		return def ;
	}
	
	public static final Integer getInt(String key,int def) {
		if(!bundle.containsKey(key)){
			return def ;
		}
		String val = bundle.getString(key);
		if(val == null )
			return def ;
		
		try{
			return Integer.parseInt(val);
		}catch(NumberFormatException ne){
			return def ;
		}
	}
	
	public static final Long getLong(String key,Long def) {
		if(!bundle.containsKey(key)){
			return def ;
		}
		String val = bundle.getString(key);
		if(val == null )
			return def ;
		
		try{
			return Long.parseLong(val);
		}catch(NumberFormatException ne){
			return def ;
		}
	}

	public static String getProperty(String string) {
		return get(string);
	}

	public static long getLongProperty(String string, Long i) {
		return getLong(string,i);
	}

	public static boolean getBooleanProperty(String string, boolean b) {
		// TODO Auto-generated method stub
		return false;
	}
	
}
